﻿using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using YouLu.Users;

namespace Shared.Service.Logging.ApplicationInsights
{
    public class CustomTelemetryInitializer : ITelemetryInitializer
    {
        private readonly ICurrentUser _user;
        public CustomTelemetryInitializer(ICurrentUser user)
        {
            _user = user;
        }
        public void Initialize(ITelemetry telemetry)
        {
            if (!string.IsNullOrEmpty(_user?.UserId))
            {
                telemetry.Context.User.Id = _user.UserId;
            }
        }
    }
}

